// 导入request
import http from "@utils/request";
import type { IRes } from "@interface";

interface IChatSaveData extends IRes {
  data: {
    chatId: number; //会话ID
  };
}

interface IChatSaveParams {
  userId: string; //用户ID
  type: number; //对话类型
  assistantId: number; //程序员助手ID
}

// 新建提问助手
export const chatSave = (data: IChatSaveParams) =>
  http.post<IChatSaveData>("/xlx-chat/chat/save", data);

export interface IChatItem {
  id: number;
  userId: number;
  created: string;
  updated: string;
  question: string;
  type: number;
  assistantId: null;
  identity: null;
  occupation: null;
  workTime: null;
  technology: null;
  dateType: string;
}
interface IChatListData extends IRes {
  data: IChatItem[];
}
interface IChatParams {
  userId: string; //用户ID
  type: string; //类型
  functionType?: number; //功能类型对话类型
  page?: number; //	当前页数
  pageSize?: number; //分页大小
}
// 查询用户提问会话列表
export const chatList = (data: IChatParams) =>
  http.get<IChatListData>("/xlx-chat/chat/list", data);
interface IChatMessageParams {
  chatId: string; //会话ID
  page?: number; //	当前页数
  pageSize?: number; //分页大小
}

interface IchatUpdate extends IRes {
  data: string;
}
// 更改对话助手标题
export const chatUpdate = (id: string, question: string) =>
  http.post<IchatUpdate>("/xlx-chat/chat/update", { id, question });
// 删除提问助手
export const chatDelete = (ids: string) =>
  http.get<IchatUpdate>("/xlx-chat/chat/delete", { ids });

// 智能对话-聊天记录
export const chatMessageList = (data: IChatMessageParams) =>
  http.get<IChatListData>("/xlx-chat/chatMessage/list", data);

export interface IAssistantItem {
  assistantId: number; //助手ID
  createUser: string; //创建人
  avatar?: string; // 可选字段，头像链接
  icon: string; //图标
  title: string; //标题
  tag: string; //详细信息
  code: string; //新建列表时 type值
}
interface IAssistantList extends IRes {
  data: IAssistantItem[];
}
// 查询程序员功能列表
export const assistantList = () =>
  http.get<IAssistantList>("/xlx-chat/assistant/list");

export interface IsubLevelModelItem {
  id: number;
  years: string;
}
export interface IIdentityItem {
  id: number;
  name: string;
  subLevelModelList: IsubLevelModelItem[];
}
interface IIdentityList extends IRes {
  data: IIdentityItem[];
}
// 查询身份信息列表
export const identityList = () =>
  http.post<IIdentityList>("/xlx-chat/chat/interview/identityList");

interface ISubLevelModel {
  code: number;
  name: string;
  duty?: string; // 使用可选属性，因为不是所有对象都有 'duty'
  parentCode: string;
  parentId: number;
  subLevelModelList?: ISubLevelModel[];
}
export interface IOccupationItem {
  id: number;
  code: number;
  name: string;
  subLevelModelList: ISubLevelModel[];
}
interface IOccupationList extends IRes {
  data: IOccupationItem[];
}
// 查询行业信息
export const occupationList = () =>
  http.post<IOccupationList>("/xlx-chat/chat/interview/occupationList");

interface IConfirmIdentityParams {
  chatId: string;
  identity: string;
  userId: string;
  years: string;
  post: string;
}
// 确认身份
export const confirmIdentity = (data: IConfirmIdentityParams) =>
  http.post<IOccupationList>("/xlx-chat/chat/interview/confirmIdentity", data);

// 获取回话详细信息
export const chatGet = (id:string) =>
  http.get<IAssistantList>("/xlx-chat/chat/get",{id});
